<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Zend_Controller Basics - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.controller.basics.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.controller.basics.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.controller.quickstart.html">Zend_Controller Quick Start</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.controller.html">Zend_Controller</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.controller.front.html">The Front Controller</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.controller.basics" class="section"><div class="info"><h1 class="title">Zend_Controller Basics</h1></div>
    

    <p class="para">
        The <span class="classname">Zend_Controller</span> system is designed to be
        lightweight, modular, and extensible. It is a minimalist design to
        permit flexibility and some freedom to users while providing enough
        structure so that systems built around <span class="classname">Zend_Controller</span>
        share some common conventions and similar code layout.
    </p>

    <p class="para">
        The following diagram depicts the workflow, and the narrative following
        describes in detail the interactions:
    </p>

    <p class="para">
        <div class="inlinemediaobject"><div class="imageobject"><a href="images/d481d625821a97b9a5eb2cec99dca50e-zend.controller.basics.png"><img src="images/d481d625821a97b9a5eb2cec99dca50e-zend.controller.basics.png" alt="zend.controller.basics.png" width="450" height="525" /></a></div></div>
    </p>

    <p class="para">
        The <span class="classname">Zend_Controller</span> workflow is implemented by several
        components. While it is not necessary to completely understand the
        underpinnings of all of these components to use the system, having a
        working knowledge of the process is helpful.
    </p>

    <ul class="itemizedlist">
        <li class="listitem">
            <p class="para">
                <span class="classname">Zend_Controller_Front</span> orchestrates the entire
                workflow of the <span class="classname">Zend_Controller</span> system. It is
                an interpretation of the FrontController pattern.
                <span class="classname">Zend_Controller_Front</span> processes all requests
                received by the server and is ultimately responsible for
                delegating requests to ActionControllers
                (<span class="classname">Zend_Controller_Action</span>).
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <span class="classname">Zend_Controller_Request_Abstract</span> (often
                referred to as the <em class="emphasis">Request Object</em>) represents
                the request environment and provides methods for setting and
                retrieving the controller and action names and any request
                parameters. Additionally it keeps track of whether or not
                the action it contains has been dispatched by
                <span class="classname">Zend_Controller_Dispatcher</span>. Extensions to the
                abstract request object can be used to encapsulate the
                entire request environment, allowing routers to pull
                information from the request environment in order to set the
                controller and action names.
            </p>

            <p class="para">
                By default, <span class="classname">Zend_Controller_Request_Http</span> is
                used, which provides access to the entire <acronym class="acronym">HTTP</acronym> request
                environment.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <span class="classname">Zend_Controller_Router_Interface</span> is used to
                define routers. Routing is the process of examining the
                request environment to determine which controller, and
                action of that controller, should receive the request. This
                controller, action, and optional parameters are then set in
                the request object to be processed by
                <span class="classname">Zend_Controller_Dispatcher_Standard</span>. Routing
                occurs only once: when the request is initially received and
                before the first controller is dispatched.
            </p>

            <p class="para">
                The default router,
                <span class="classname">Zend_Controller_Router_Rewrite</span>, takes a
                <acronym class="acronym">URI</acronym> endpoint as specified in
                <span class="classname">Zend_Controller_Request_Http</span> and decomposes it
                into a controller, action, and parameters based on the path information
                in the <acronym class="acronym">URL</acronym>. As an example, the <acronym class="acronym">URL</acronym>
                <var class="filename">http://localhost/foo/bar/key/value</var> would be
                decoded to use the <em class="emphasis">foo</em> controller,
                <em class="emphasis">bar</em> action, and specify a parameter
                <em class="emphasis">key</em> with a value of <em class="emphasis">value</em>.
            </p>

            <p class="para">
                <span class="classname">Zend_Controller_Router_Rewrite</span> can also be used
                to match arbitrary paths; see <a href="zend.controller.router.html" class="link">the router documentation</a>
                for more information.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <span class="classname">Zend_Controller_Dispatcher_Interface</span> is used to
                define dispatchers. Dispatching is the process of pulling
                the controller and action from the request object and
                mapping them to a controller file (or class) and action method in
                the controller class. If the controller or action do not
                exist, it handles determining default controllers and
                actions to dispatch.
            </p>

            <p class="para">
                The actual dispatching process consists of instantiating the
                controller class and calling the action method in that
                class. Unlike routing, which occurs only once, dispatching
                occurs in a loop. If the request object&#039;s dispatched status
                is reset at any point, the loop will be repeated, calling
                whatever action is currently set in the request object. The
                first time the loop finishes with the request object&#039;s
                dispatched status set (<span class="type">Boolean</span> <b><tt>TRUE</tt></b>),
                it will finish processing.
            </p>

            <p class="para">
                The default dispatcher is
                <span class="classname">Zend_Controller_Dispatcher_Standard</span>. It defines
                controllers as MixedCasedClasses ending in the word
                Controller, and action methods as camelCasedMethods ending
                in the word Action:
                 <span class="methodname">FooController::barAction()</span>. In this case, the
                controller would be referred to as <em class="emphasis">foo</em> and
                the action as <em class="emphasis">bar</em>.
            </p>

            <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Case Naming Conventions</b><br /></span>
                

                <p class="para">
                    Since humans are notoriously inconsistent at
                    maintaining case sensitivity when typing links, Zend
                    Framework actually normalizes path information to
                    lowercase. This, of course, will affect how you name
                    your controller and actions... or refer to them in
                    links.
                </p>

                <p class="para">
                    If you wish to have your controller class or action
                    method name have multiple MixedCasedWords or
                    camelCasedWords, you will need to separate those words
                    on the url with either a &#039;-&#039; or &#039;.&#039; (though you can
                    configure the character used).
                </p>

                <p class="para">
                    As an example, if you were going to the action in
                     <span class="methodname">FooBarController::bazBatAction()</span>, you&#039;d
                    refer to it on the url as <var class="filename">/foo-bar/baz-bat</var>
                    or <var class="filename">/foo.bar/baz.bat</var>.
                </p>
            </p></blockquote>
        </li>

        <li class="listitem">
            <p class="para">
                <span class="classname">Zend_Controller_Action</span> is the base action
                controller component. Each controller is a single class
                that extends the <span class="classname">Zend_Controller_Action</span> class
                and should contain one or more action methods.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <span class="classname">Zend_Controller_Response_Abstract</span> defines a
                base response class used to collect and return responses
                from the action controllers. It collects both headers and
                body content.
            </p>

            <p class="para">
                The default response class is
                <span class="classname">Zend_Controller_Response_Http</span>, which is
                suitable for use in an <acronym class="acronym">HTTP</acronym> environment.
            </p>
        </li>
    </ul>

    <p class="para">
        The workflow of <span class="classname">Zend_Controller</span> is relatively simple. A
        request is received by <span class="classname">Zend_Controller_Front</span>, which in turn
        calls <span class="classname">Zend_Controller_Router_Rewrite</span> to determine which
        controller (and action in that controller) to dispatch.
        <span class="classname">Zend_Controller_Router_Rewrite</span> decomposes the <acronym class="acronym">URI</acronym>
        in order to set the controller and action names in the request.
        <span class="classname">Zend_Controller_Front</span> then enters a dispatch loop. It
        calls <span class="classname">Zend_Controller_Dispatcher_Standard</span>, passing it the
        request, to dispatch to the controller and action specified in the
        request (or use defaults). After the controller has finished, control
        returns to <span class="classname">Zend_Controller_Front</span>. If the controller has
        indicated that another controller should be dispatched by resetting the
        dispatched status of the request, the loop continues and another
        dispatch is performed. Otherwise, the process ends.
    </p>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.controller.quickstart.html">Zend_Controller Quick Start</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.controller.html">Zend_Controller</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.controller.front.html">The Front Controller</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="reference.html">Zend Framework Reference</a></li>
  <li class="header up"><a href="zend.controller.html">Zend_Controller</a></li>
  <li><a href="zend.controller.quickstart.html">Zend_Controller Quick Start</a></li>
  <li class="active"><a href="zend.controller.basics.html">Zend_Controller Basics</a></li>
  <li><a href="zend.controller.front.html">The Front Controller</a></li>
  <li><a href="zend.controller.request.html">The Request Object</a></li>
  <li><a href="zend.controller.router.html">The Standard Router</a></li>
  <li><a href="zend.controller.dispatcher.html">The Dispatcher</a></li>
  <li><a href="zend.controller.action.html">Action Controllers</a></li>
  <li><a href="zend.controller.actionhelpers.html">Action Helpers</a></li>
  <li><a href="zend.controller.response.html">The Response Object</a></li>
  <li><a href="zend.controller.plugins.html">Plugins</a></li>
  <li><a href="zend.controller.modular.html">Using a Conventional Modular Directory Structure</a></li>
  <li><a href="zend.controller.exceptions.html">MVC Exceptions</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>